/**
 * 登出操作，清除
 * */
import {
  cleanSessionStorage,
  getCurrentPosInfo,
  removeAuthorization,
  removeCompanyID,
  removeCompanyName,
  removeCurrentPosInfo,
  removeCurrentRouteObj,
  removeLevelFirst,
  removeLevelSecond,
  removeLevelSecondJson,
  removeLevelZero,
  removeLevelZeroJson,
  removePosIDs,
  removePosName,
  removeTenant,
  removeTenantID,
  removeTheme,
  removeUserDepID,
  removeUserDutyDepID,
  removeUserDepName,
  removeUserID,
  removeUserName,
  removeUserShortCode,
  setTenant,
  removeUserDeptFlag,
  removeOAPosIDs,
} from './authority';

import { history } from 'umi';
import { getSystemTypeValue } from './myutilTwo';

export const logout = async (name: 'hrky') => {
  try {
    //清除主题样式
    let themeStyle = document.getElementById('less:styles-components');
    if (themeStyle) {
      themeStyle.remove();
    }

    /*清除缓存*/
    removeAuthorization();
    removeCompanyID();
    removeLevelFirst();
    removeLevelSecond();
    removePosIDs();
    removeTenant();
    removeTenantID();
    removeTheme();
    removeUserDepID();
    removeUserDutyDepID();
    removeUserID();
    removeUserName();
    removeUserDepName();
    removePosName();
    removeCompanyName();

    removeCurrentRouteObj(); //清除存入的当前路由数据
    removeLevelSecondJson(); //清除职权范围数据;
    removeLevelZeroJson(); //清除职权范围数据
    removeLevelZero(); //清除职权范围数据
    // cleanSessionStorage();
    removeUserShortCode(); //清除当前用户组织简码
    removeCurrentPosInfo(); //清除当前岗位详情
    removeUserDeptFlag(); //清除当前岗位是否科研机构
    removeOAPosIDs(); //清除oa携带岗位id

    setTenant(name);
    history.push(`/login/${name}?state=${getSystemTypeValue()}`); //[测试]
    // window.location.href = 'http://id.uat.hrl.ac.cn:8081' //[UAT环境打包]
    // window.location.href = 'http://id.hrl.ac.cn:8081' //[生产环境打包]
  } catch (e) {}
};
